<?php get_header(); ?>
<?php $cur_post = $post; ?>

<script>
  $(document).ready(function(){
    $(".date").collapse({show: function(){
        this.animate({
          opacity: 'toggle', 
          height: 'toggle'
        }, 300);
      },
      hide : function() {
        this.animate({
            opacity: 'toggle', 
            height: 'toggle'
        }, 300);
      }
    });
    
    $('.date .field:eq(0)').css('display', 'block');
    $('.date h4:eq(0)').attr('class', 'active');
  });
</script>

<div class="content-top"></div>
<div class="content-bottom news-detail">
  <div class="wrapper">
    <?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
    
    <div class="content-sidebar">
      <div class="sidebar-title">
        <h3>NEWS</h3>
        <h4>NEWS ARCHIEVE</h4>
      </div>
      
      <div class="sidebar-content">
        <div class="date">
          <?php 
          $counter =0;
          
          foreach(get_the_category() as $category)
          { $thecat = $category->cat_ID; } ?>
          <?php query_posts('cat=' . $thecat); ?>
          <?php if (have_posts()) : ?>
          <?php while (have_posts()) : the_post(); ?>
          
          <?php
            // check if final post
            $counter++;
            if($counter == $wp_query->post_count){
              $counter = 0;
              
            };
          ?>
          
          <?php $year = the_date('F Y', '', '', FALSE); ?>
            <?php 
               // If your year hasn't been echoed earlier in the loop, echo it now
               if ($year !== $year_check) {
                
                if($year_check != ''){
                  echo '</div>';
                }
                
                echo "<h4>" . $year . "</h4>";
                echo '<div class="field">';
               }
               // Now that your year has been printed, assign it to the $year_check variable
               $year_check = $year;
            ?>
            
              <div class="post">
                <h5><?php the_time('j F Y') ?></h5>
                <?php 
                  $mycontent = getWords(get_the_content(), 20);
                  echo apply_filters('the_content', $mycontent); 
                ?>
                <a href="<?php echo get_permalink(); ?>">Read More...</a>
              </div><!-- end .post-wrap -->

          <?php endwhile; ?>
          <?php endif; ?>
          </div>
        </div>
      </div>
    </div>
    <div class="news-content">
      <div class="news-big-content">
        <h4><?php echo date('d/n/Y', strtotime($cur_post->post_date)); ?></h4>
        
        <h3><?php echo $cur_post->post_title; ?></h3>
        
        <?php if ( has_post_thumbnail() ) { ?>
          <div class="picture-frame">
            <?php the_post_thumbnail(); ?>
          </div>
        <?php } ?>
        
        <?php echo the_content(); ?>
      </div>
    </div>
  </div>
</div>

<?php get_footer(); ?>
